package org.facyt.vacas.view.formulacion.field;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.facyt.commons.util.Constantes;
import org.facyt.commons.util.VaadinUtil;
import org.facyt.commons.view.field.BaseComboBox;
import org.facyt.vacas.entities.vacas.MateriaPrima;
import org.facyt.vacas.services.MateriasPrimasService;
import org.facyt.vacas.services.impl.MateriasPrimasServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MateriaPrimaComboBox extends BaseComboBox<MateriaPrima> {

	private static final long serialVersionUID = -1792094842590047908L;
	private static final Log logger = LogFactory
			.getLog(MateriaPrimaComboBox.class);

	@Autowired
	private MateriasPrimasService materiaPrimasService;

	public MateriaPrimaComboBox() {
		super(VaadinUtil.getProperties("combobox.materia.prima.default.value"));
	}

	public MateriaPrimaComboBox(String caption, String captionNullSelection) {
		super(caption, VaadinUtil
				.getProperties("combobox.materia.prima.default.value"));

	}

	@Override
	protected Object getItemCaptionProperty() {
		return MateriaPrima.Atributos.DESCRIPCION;
	}

	@Override
	protected Collection<? extends MateriaPrima> getItems() {
		List<MateriaPrima> listaMateriaPrima = new ArrayList<MateriaPrima>();

		try {
			listaMateriaPrima = materiaPrimasService.getTodasMateriasPrima(1L);
		} catch (Exception e) {
			logger.error(Constantes.ErrorLoggin.ERROR, e);
			return new ArrayList<MateriaPrima>();
		}

		return listaMateriaPrima;
	}

}
